package com.foreveross.taskservice.engine.worker;

import org.apache.log4j.Logger;
import org.dayatang.domain.InstanceFactory;
import org.quartz.InterruptableJob;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.UnableToInterruptJobException;

import com.foreveross.taskservice.application.channel.IGradChannelApplication;
import com.foreveross.taskservice.application.statistics.hbase.StaticHistoryApplication;
import com.foreveross.taskservice.application.task.mq.IMQInfoApplication;
import com.foreveross.taskservice.application.task.mq.IRollbackTaskFromMQApplication;
import com.foreveross.taskservice.application.task.mq.ITaskToMQApplication;
import com.foreveross.taskservice.application.task.service.IBuildTaskQueueLogApplication;
import com.foreveross.taskservice.application.task.service.IBuildTaskToCacheApplication;
import com.foreveross.taskservice.application.task.service.ITaskQueueLogApplication;
import com.foreveross.taskservice.application.task.service.ITaskTemplateApplication;
import com.foreveross.taskservice.infra.util.SpringHelper;
import com.foreveross.taskservice.taskcache.ITaskCacheFlush;
import com.foreveross.taskservice.taskcache.ITaskCacheQuery;
import com.foreveross.taskservice.taskcache.ITaskCacheStorage;

/**
 * 
 * @author Administrator
 * 
 */
public  class BaseJobWorker implements InterruptableJob{

	protected final Logger log = Logger.getLogger(getClass());
	private ITaskTemplateApplication taskTemplateApplication;
	private IGradChannelApplication gradChannelApplication;
	private ITaskCacheStorage taskCacheStorage;
	private ITaskCacheQuery taskCacheQuery;
	private ITaskCacheFlush taskCacheFlush;
	private IBuildTaskQueueLogApplication buildTaskQueueLogApplication;
	private IBuildTaskToCacheApplication buidBuildTaskToCacheApplication;
	private ITaskToMQApplication taskToMQApplication;
	private IRollbackTaskFromMQApplication rollbackTaskFromMQApplication;
	private ITaskQueueLogApplication taskQueueLogApplication;
	private IMQInfoApplication mqInfoApplication;

	protected StaticHistoryApplication staticHistoryApplication;
	
	public BaseJobWorker() {
		taskTemplateApplication = InstanceFactory.getInstance(
				ITaskTemplateApplication.class, "taskTemplateApplicationImpl");
		gradChannelApplication = InstanceFactory.getInstance(
				IGradChannelApplication.class, "gradChannelApplicationImpl");
		buildTaskQueueLogApplication = InstanceFactory.getInstance(
				IBuildTaskQueueLogApplication.class,
				"buildTaskQueueLogApplicationImpl");
		buidBuildTaskToCacheApplication = InstanceFactory.getInstance(
				IBuildTaskToCacheApplication.class,
				"buildTaskToCacheApplicationImpl");
		taskToMQApplication = InstanceFactory.getInstance(
				ITaskToMQApplication.class, "taskToMQApplicationImpl");
		rollbackTaskFromMQApplication = InstanceFactory.getInstance(
				IRollbackTaskFromMQApplication.class,
				"rollbackTaskFromMQApplicationImpl");
		taskQueueLogApplication = InstanceFactory.getInstance(
				ITaskQueueLogApplication.class, "taskQueueLogApplicationImpl");
		taskCacheStorage = InstanceFactory.getInstance(ITaskCacheStorage.class,
				"redisTaskCacheStorageImpl");
		taskCacheQuery = InstanceFactory.getInstance(ITaskCacheQuery.class,
				"redisTaskCacheQueryImpl");
		taskCacheFlush = InstanceFactory.getInstance(ITaskCacheFlush.class,
				"redisTaskCacheFlushImpl");
		mqInfoApplication = InstanceFactory
				.getInstance(IMQInfoApplication.class);
		
		staticHistoryApplication=InstanceFactory.getInstance(StaticHistoryApplication.class,"staticHistoryApplicationImpl");
//		staticHistoryApplication=(StaticHistoryApplication)SpringHelper.getBean(StaticHistoryApplication.class);
	}

	public Logger getLog() {
		return log;
	}

	public ITaskTemplateApplication getTaskTemplateApplication() {
		return taskTemplateApplication;
	}

	public IGradChannelApplication getGradChannelApplication() {
		return gradChannelApplication;
	}

	public IBuildTaskQueueLogApplication getBuildTaskQueueLogApplication() {
		return buildTaskQueueLogApplication;
	}

	public IBuildTaskToCacheApplication getBuidBuildTaskToCacheApplication() {
		return buidBuildTaskToCacheApplication;
	}

	public ITaskToMQApplication getTaskToMQApplication() {
		return taskToMQApplication;
	}

	public IRollbackTaskFromMQApplication getRollbackTaskFromMQApplication() {
		return rollbackTaskFromMQApplication;
	}

	public ITaskQueueLogApplication getTaskQueueLogApplication() {
		return taskQueueLogApplication;
	}

	public ITaskCacheStorage getTaskCacheStorage() {
		return taskCacheStorage;
	}

	public ITaskCacheQuery getTaskCacheQuery() {
		return taskCacheQuery;
	}

	public ITaskCacheFlush getTaskCacheFlush() {
		return taskCacheFlush;
	}

	public IMQInfoApplication getMqInfoApplication() {
		return mqInfoApplication;
	}

	@Override
	public void execute(JobExecutionContext context)
			throws JobExecutionException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void interrupt() throws UnableToInterruptJobException {
		// TODO Auto-generated method stub
		
	}

	
	

}
